//
//  CWCFunnyCell.m
//  ChuanNews
//
//  Created by dllo on 16/4/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CWCFunnyCell.h"
#import "BaseHeader.h"
@implementation CWCFunnyCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.digestLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 20, 355, 100)];
        self.digestLabel.numberOfLines = 0;
        self.digestLabel.font = [UIFont systemFontOfSize: 17];
        [self.contentView addSubview:self.digestLabel];
        
        [self jxl_setDayMode:^(UIView *view) {
            CWCFunnyCell *cell = (CWCFunnyCell *)view;
            cell.backgroundColor = [UIColor whiteColor];
            cell.contentView.backgroundColor = [UIColor whiteColor];
            cell.digestLabel.backgroundColor = [UIColor whiteColor];
            cell.digestLabel.textColor = [UIColor blackColor];
        } nightMode:^(UIView *view) {
            CWCFunnyCell *cell = (CWCFunnyCell *)view;
            cell.backgroundColor = [UIColor blackColor];
            cell.contentView.backgroundColor = [UIColor blackColor];
            cell.digestLabel.backgroundColor = [UIColor blackColor];
            cell.digestLabel.textColor = [UIColor whiteColor];        }];

    }
    return self;
}

+ (CGFloat)textLabelHeight:(NSString *)text{
    CGSize size = CGSizeMake(355, 3750);
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:18]};
    CGRect rect = [text boundingRectWithSize:size options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dic context:nil];
    return  rect.size.height;
}
-(void)setModel:(CWCFunModel *)model{
    if (_model != model) {
        _model = model;
        self.digestLabel.text = model.digest;
        CGFloat height = [[self class] textLabelHeight:self.model.digest];
        CGRect frame = self.digestLabel.frame;
        frame.size.height = height;
        self.digestLabel.frame = frame;
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
